package com.zx.system.block.mapstruct;

import com.zx.core.enums.StatusEnum;
import com.zx.system.block.model.SysTenant;
import com.zx.system.block.param.TenantParam;
import com.zx.system.block.vo.SysTenantVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

/**
 * <p>
 * description: 租户参数映射 <br>
 * create: 2025-11-23
 * </p>
 *
 * @author zhou xun
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TenantMapStructMapper {
    TenantMapStructMapper INSTANCE = Mappers.getMapper(TenantMapStructMapper.class);

    /**
     * 将TenantParam转换为SysTenant实体
     *
     * @param tenantParam 租户参数
     * @return SysTenant实体
     */
    SysTenant tenantParamToSysTenant(TenantParam tenantParam);

    /**
     * 将SysTenant实体转换为SysTenantVO视图对象
     *
     * @param sysTenant 租户实体
     * @return SysTenantVO视图对象
     */
    SysTenantVO sysTenantToSysTenantVO(SysTenant sysTenant);

    /**
     * 在映射完成后，设置描述性字段
     *
     * @param sysTenant   租户实体
     * @param sysTenantVO 租户VO
     */
    @AfterMapping
    default void setDescriptions(SysTenant sysTenant, @MappingTarget SysTenantVO sysTenantVO) {
        // 设置状态描述
        Integer status = sysTenant.getStatus();
        StatusEnum statusEnum = StatusEnum.getEnumByCode(status);
        if (statusEnum != null) {
            sysTenantVO.setStatusDesc(statusEnum.getDesc());
        }
    }
}